// Fill out your copyright notice in the Description page of Project Settings.


#include "Test/PopupBox/Toast/ToastWidget.h"
#include "Test/PopupBox/Toast/SToastSlate.h"

UToastWidget::UToastWidget()
{
	ShowMask = false;
	// MaskBrush = FCoreStyle::Get().GetBrush("Border");
	ShowIcon = false;
	// IconBrush = FCoreStyle::Get().GetDefaultBrush();
	IconSize = FVector2D(250.f);
	ToastText = FText();
	// TextFont = &FCoreStyle::Get().GetWidgetStyle<FTextBlockStyle>("NormalText");
	// ScrollBrush = &FCoreStyle::Get().GetWidgetStyle<FScrollBarStyle>("Scrollbar");
	ToastSize = FVector2D(800.f, 600.f);
	ToastPadding = FMargin(20.f);
	// ToastBrush = FCoreStyle::Get().GetBrush("Border");
}

void UToastWidget::SynchronizeProperties()
{
	Super::SynchronizeProperties();

	TAttribute<FText> TextBinding = PROPERTY_BINDING(FText, ToastText);
	MyToastSlate->SetToastText(TextBinding);
	MyToastSlate->SetShowMask(ShowMask);
	MyToastSlate->SetMaskBrush(&MaskBrush);
	MyToastSlate->SetShowIcon(ShowIcon);
	MyToastSlate->SetIconBrush(&IconBrush);
	MyToastSlate->SetIconSize(IconSize);
	MyToastSlate->SetTextFont(&TextFont);
	MyToastSlate->SetTextBackground(&TextBackground);
	MyToastSlate->SetScrollBrush(&ScrollBrush);
	MyToastSlate->SetToastSize(ToastSize);
	MyToastSlate->SetToastPadding(ToastPadding);
	MyToastSlate->SetToastBrush(&ToastBrush);
}

TSharedRef<SWidget> UToastWidget::RebuildWidget()
{
	MyToastSlate = SNew(SToastSlate)
		.ToastSize(ToastSize)
		.ToastPadding(ToastPadding)
		// .ToastBrush(&ToastBrush)
		.ToastText(ToastText)
		// .TextFont(&TextFont)
		// .ScrollBrush(&ScrollBrush)
		.ShowIcon(ShowIcon)
		// .IconBrush(&IconBrush)
		.IconSize(IconSize)
		.ShowMask(ShowMask)
		// .MaskBrush(&MaskBrush)
		;
	return MyToastSlate.ToSharedRef();
}

void UToastWidget::ReleaseSlateResources(bool bReleaseChildren)
{
	Super::ReleaseSlateResources(bReleaseChildren);
	MyToastSlate.Reset();
}

#if WITH_EDITOR

const FText UToastWidget::GetPaletteCategory()
{
	return NSLOCTEXT("ElementUI", "ElementUICategory", "ElementUI");
}

#endif
